﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Csla.Wpf;
using OpenExpressApp.Template;
using Itenso.Windows.Input;
using OpenExpressApp.Module;
using OpenExpressApp.Module.WPF;
using OpenExpressApp.Module.WPF.Templete;
using OpenExpressApp.Types;
using OpenExpressApp.MetaModel;
using OpenExpressApp.Command;

namespace OpenExpressApp.WPF.Templete
{
    public partial class PopupForm : WindowTemplateBase
    {
        private PopupFormController _controller;

        #region 构造函数

        /// <summary>
        /// 自动获取数据的窗口
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="getListParam"></param>
        public PopupForm(Type entityType, params Object[] getListParam)
            : this(entityType)
        {
            if (this.HasQueryPanel() == false)
            {
                this.ListView.DataLoader.AsyncGetObject(getListParam);
            }
        }

        /// <summary>
        /// 自动获取数据的窗口
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="getListMethod"></param>
        /// <param name="getListParam"></param>
        public PopupForm(Type entityType, string getListMethod, params Object[] getListParam)
            : this(entityType)
        {
            if (this.HasQueryPanel() == false)
            {
                this.ListView.DataLoader.AsyncGetObject(getListMethod, getListParam);
            }
        }

        /// <summary>
        /// 没有任何数据的窗口，
        /// 需要设置View.Data
        /// </summary>
        /// <param name="entityType"></param>
        public PopupForm(Type entityType)
            : base(entityType)
        {
            this.InitializeComponent();

            this._controller = new PopupFormController(this);
        }

        #endregion

        public override IFrameController Controller
        {
            get { return this._controller; }
        }

        public override ModuleType ModuleType
        {
            get
            {
                return ModuleType.Popup;
            }
        }

        public override void LayoutQueryPanel()
        {
            LayoutQueryPanel(this.ListView, queryPane, dcCondition, dcNavigate);

            //自动隐藏查询面板
            if (ApplicationModel.GetBusinessObjectInfo(RootEntityType).AutoHideQueryPane)
            {
                queryPane.GetManager().ToggleAutoHide(queryPane);
            }
        }

        public override object GetRegion(string regionName)
        {
            switch (regionName)
            {
                case ViewRegionNames.ListRegion:
                    return listRegion;
                case ViewRegionNames.ConditionQueryRegion:
                    return conditionQueryRegion;
                case ViewRegionNames.NavigateQueryRegion:
                    return navigateQueryRegion;
                default:
                    return null;
            }
        }
    }
}
